package com.czk.controller;

import com.czk.entity.PageResult;
import com.czk.entity.Result;
import com.czk.entity.StatusCode;
import com.czk.model.TbOperateLog;
import com.czk.servcie.OperateLogService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/10/21 15:45
 */
@RestController
@RequestMapping("/operateLog")
public class OperateLogController {
    @Resource
    private OperateLogService operateLogService;

    @PostMapping("/add")
    public Result add(@RequestBody TbOperateLog operateLog) {
        operateLogService.insert(operateLog);
        return new Result(true, StatusCode.OK, "插入成功", operateLog);
    }

    @PostMapping("/search/{page}/{size}")
    public Result search(@RequestBody Map<String, String> searchMap, @PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        Page page1 = operateLogService.search(searchMap, page, size);
        PageResult pageResult = new PageResult(page1.getTotal(), page1.getResult());
        return new Result(true, StatusCode.OK, "查询成功", pageResult);
    }
}
